package com.tanguy.user.ui.main

import cn.sinata.xldutils_kotlin.utils.SPUtils
import com.tanguy.user.App.Companion.app
import com.tanguy.user.Const
import com.tanguy.user.R
import com.tanguy.user.base.ImmersionTitleActivity
import com.tanguy.user.net.http.HttpManager
import com.tanguy.user.utlis.extend.loge
import com.tanguy.user.utlis.extend.request
import org.jetbrains.anko.startActivity

/**
 * Created by dab on 2017/11/20 0020 11:37
 * 启动页
 */
class LauncherActivity : ImmersionTitleActivity() {
    override fun setContentViewRes(): Int = R.layout.activity_launcher
    override fun fullScreen(): Boolean = true
    override fun initView() {
        super.initView()
        val id = SPUtils.instance().getInt(Const.User.ID, 0)
        if (id <= 0) {
            startActivity<MainActivity>()
            finish()
        } else {
            HttpManager.getUserinfo(id)
                    .request(this, false) {
                        if (it != null && it.code == 0 && it.data != null && it.data!!.state == 1) {
                            app.user = it.data!!
                            app.user.userId = id
                            loge(it.data!!.toString())
                        }
                        startActivity<MainActivity>()
                        finish()
                    }
        }

    }
}